package com.hymall.controller.admin;

import com.hymall.bean.MarketCategory;

import com.hymall.bean.common.BaseRespVo;
import com.hymall.bean.common.CommonData;
import com.hymall.bean.vo.CategoryCreateVo;
import com.hymall.service.admin.AdminCategoryService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;


/**
 * @author: 周子伟
 * @description ${ 商场管理 商品类目}
 * @date: 2022/7/17 20:58
 */

@RestController
@RequestMapping("admin/category")
public class AdminCategoryController {

    @Autowired
    AdminCategoryService adminCategoryService;


    @GetMapping("l1")
    /*
     * @author Invoker
     * @description {查找一级商品类目L1}
     * @date 2022/7/18 11:09
     * @param []
     * @return com.hymall.bean.common.BaseRespVo
     */
    public BaseRespVo listL1() {
        String level = "L1";
        CommonData data = adminCategoryService.queryCategoryL1(level);
        return BaseRespVo.ok(data);
    }

    @GetMapping("list")


    /*
     * @author Invoker
     * @description {实现查找商品类目的功能}
     * @date 2022/7/18 17:30
     * @param []
     * @return com.hymall.bean.common.BaseRespVo
     */
    public BaseRespVo list() {
        String level = "L1";
        CommonData data = adminCategoryService.queryCategory(level);

        return BaseRespVo.ok(data);

    }


    /*
    * @author Invoker
    * @description {新增类目}
    * @date 2022/7/18 19:24
    * @param [marketCategory]
    * @return com.hymall.bean.common.BaseRespVo
    */
    @PostMapping("create")
    public BaseRespVo create(@RequestBody MarketCategory marketCategory) {

        CategoryCreateVo data = adminCategoryService.create(marketCategory);



        return BaseRespVo.ok(data);

    }





    /*
    * @author Invoker
    * @description {修改类目}
    * @date 2022/7/18 19:31
    * @param [marketCategory]
    * @return com.hymall.bean.common.BaseRespVo
    */
    @PostMapping("update")

public  BaseRespVo update(@RequestBody MarketCategory marketCategory){

          adminCategoryService.update(marketCategory);

          return  BaseRespVo.ok(null);

    }

@PostMapping("delete")
public  BaseRespVo delete(@RequestBody MarketCategory marketCategory){

        adminCategoryService.delete(marketCategory);

        return  BaseRespVo.ok(null);


}



}
